package com.atguigu.test.boot.controller;

import com.mybatis.demo.dao.IUserInfoDao;
import com.mybatis.demo.entity.UserInfo;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * @author zp
 * @version 1.0
 * @description: 测试请求类
 * @date 2023/2/7 19:10
 */
@Controller
public class HelloController {

    @Autowired
    ApplicationContext applicationContext;

    @Autowired
    SqlSession sqlSession;

    @GetMapping("/hello")
    @ResponseBody
    public String hello(){
        return "hello";
    }

    @GetMapping("/env")
    public ModelAndView getEnv(){
        System.out.println("测试环境变量配置读取："+applicationContext.getEnvironment().getProperty("jdbc.password"));
        return null;
    }

    @GetMapping("/bean")
    public ModelAndView getBean(){
        System.out.println("测试环境变量配置读取："+applicationContext.getBean("mySqlProperties").toString());
        return null;
    }

    @GetMapping("/beans")
    public ModelAndView getBeans(){
        for (String beanDefinitionName : applicationContext.getBeanDefinitionNames()) {
            System.out.println(beanDefinitionName);
        }

        return null;
    }

    @GetMapping("/sql")
    public ModelAndView getSql(){
        IUserInfoDao userInfoDao = sqlSession.getMapper(IUserInfoDao.class);
        UserInfo userInfo = userInfoDao.findById(1);
        System.out.println(userInfo);
        return null;
    }

}
